package edu.hawaii.webspider;

import java.util.logging.Logger;
import org.hackystat.utilities.logger.HackystatLogger;

/**
 * Implements a logger class for WebSpider.  It works off of the HackystatLogger
 * interface defined by Philip Johnson at http://code.google.com/p/hackystat-utilities/.  
 * 
 * <p> Logging is disabled by default because logging functions are called regardless of
 * whether or not logging is enabled - but log data is only written if logging is enabled.
 * 
 * @author Andrew Wong
 *
 */
public class WebSpiderLogger {
  boolean active;
  
  Logger logger;
  
  /**
   * Initializes the logger.
   */
  WebSpiderLogger() {
    active = false;
  }
  
  /**
   * Enables logging.
   */
  void enable() {
    logger = HackystatLogger.getLogger("edu.hawaii.webspider");
    HackystatLogger.setLoggingLevel(logger, "INFO");
    logger.info("Logging started");
    
    active = true;
  }
  
  /**
   * Logs a message to the WebSpiderLogger.
   * @param message Message to be appended to the log.
   */
  void log(String message) {
    if (active) {
      logger.info(message);
    }
  }
}
